<?php

namespace App\Observers;

use App\Models\Meeting;
use App\Models\UserInfos;
use App\Services\Sms;

class MeetingObserver
{
    /**
     * Handle the Meeting "created" event.
     *
     * @param  \App\Models\Meeting  $meeting
     * @return void
     */
    public function created(Meeting $meeting)
    {
        //
    }

    /**
     * 监听修改事件
     *
     * @param  \App\Models\Meeting  $meeting
     * @return void
     */
    public function updated(Meeting $meeting)
    {
        // 判断修改的数据是否是关闭会议的
        if ($meeting['state']==2){
            // 获取会议发起人的手机号
            $phone = UserInfos::where('id',$meeting['user_id'])->first()->toArray()['phone'];
            // 发送短息提示
            Sms::send($phone,'由于您的会议三十分钟没人进入，已关闭您的会议');
        }

    }

    /**
     * Handle the Meeting "deleted" event.
     *
     * @param  \App\Models\Meeting  $meeting
     * @return void
     */
    public function deleted(Meeting $meeting)
    {
        //
    }

    /**
     * Handle the Meeting "restored" event.
     *
     * @param  \App\Models\Meeting  $meeting
     * @return void
     */
    public function restored(Meeting $meeting)
    {
        //
    }

    /**
     * Handle the Meeting "force deleted" event.
     *
     * @param  \App\Models\Meeting  $meeting
     * @return void
     */
    public function forceDeleted(Meeting $meeting)
    {
        //
    }
}
